package com.dx.generator.util;

import java.util.HashMap;

/**
 * Description:
 * 公共的返回类
 *
 * @author rockstarsteve
 * @version 1.0
 * @copyright Copyright (c) 电信
 * @since 2023/8/19
 */
public class Result extends HashMap<String, Object> {
    public Result() {
        put("code", 0);
        put("msg", "success");
        put("other", "");
    }

    public static Result error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static Result error(String msg) {
        return error(500, msg);
    }

    public static Result error(int code, String msg) {
        Result r = new Result();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static Result ok(Object object) {
        Result r = new Result();
        r.put("data", object);
        return r;
    }

    public static Result ok() {
        return new Result();
    }

    @Override
    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
